#include"../thread_pool.h"
#include"mysql.h"
/*-------------------delimiter--------------------------------*/
void connect_mysql(user_info* user){
    //初始化MYSQL连接
    MYSQL *conn = (MYSQL*)calloc(1,sizeof(MYSQL));
    user-> pconn = mysql_init(conn);
    //与MySQL服务器建立连接
    user->pconn = mysql_real_connect(conn, "localhost", "root", "1234",
                               "Clouddisk", 0, NULL, 0);
    if (user->pconn == NULL) {
        printf("%d\n", mysql_errno(conn));
        exit(1);
    }

    //设置客户端的编码规则，防止出现乱码的情况
    mysql_query(user->pconn, "set names utf8");

    //初始化MySQL_STMT
    user->stmt = mysql_stmt_init(user->pconn);
    if (user->stmt == NULL) {
        printf("error:%s\n", mysql_error(user->pconn));
        mysql_close(user->pconn);
        exit(1);
    }
}


